import 'package:flutter/material.dart';
import 'package:flutter_eve_plugin/pages/main/actions.dart';
import 'package:flutter_eve_plugin/utils/image_util.dart';
import 'package:flutter_eve_plugin/utils/screen_util.dart';

AppBar buildAppBar(BuildContext context,
    {List<Widget> actions = const <Widget>[],
    PreferredSizeWidget bottom,
    String title = '',
    Color titleColor = Colors.white,
    List<Color> colors = const <Color>[
      Color.fromRGBO(121, 117, 255, 1),
      Color.fromRGBO(196, 174, 255, 1),
    ],
    FigureIP type = FigureIP.HU_PO}) {
  return type == FigureIP.HU_PO
      ? AppBar(
          title: Text(
            title,
            style: TextStyle(fontSize: setTextSp(17), color: titleColor),
          ),
          centerTitle: true,
          elevation: 0,
          bottom: bottom,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: colors,
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
              ),
            ),
          ),
          leading: Builder(
            builder: (BuildContext context) {
              return IconButton(
                icon: Image.asset(
                  imageUtilHuPo('main/icon_navbar_back@2x'),
                  width: setRatio(22),
                  height: setRatio(42),
                ),
                onPressed: () {
                  Navigator.canPop(context)
                      ? Navigator.pop(context)
                      : goBackNative();
                },
              );
            },
          ),
          actions: actions,
        )
      : AppBar(
          title: Text(
            title,
            style: TextStyle(fontSize: setTextSp(17), color: titleColor),
          ),
          centerTitle: true,
          elevation: 0,
          bottom: bottom,
          flexibleSpace: Container(
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: colors,
                begin: Alignment.centerLeft,
                end: Alignment.centerRight,
              ),
            ),
          ),
          leading: Builder(
            builder: (BuildContext context) {
              return IconButton(
                icon: Image.asset(
                  imageUtilYeXiu('main/icon_back@2x'),
                  width: setRatio(10),
                  height: setRatio(18),
                ),
                onPressed: () {
                  Navigator.canPop(context)
                      ? Navigator.pop(context)
                      : goBackNative();
                },
              );
            },
          ),
          actions: actions,
        );
}
